<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { memberOrderId } from '@/api/order.js'
import GoodDialog from '@/views/user/order/components/goodDialog.vue'
import router from '@/router'

const tableData = ref([{}])
const active = ref(0)
const route = useRoute()
const data = ref()
const getData = async () => {
  const res = await memberOrderId(route.params.id)
  data.value = res.data.result
  tableData.value = data.value.skus
  active.value = data.value.orderState
}
getData()
const getState = state => {
  switch (state) {
    case 1:
      return '待付款'

    case 2:
      return '待发货'

    case 3:
      return '待收货'

    case 4:
      return '待评价'

    case 5:
      return '已完成'

    case 6:
      return '已取消'
  }
}
const getChannel = data => {
  if (data === 1) return '支付宝'
  if (data === 2) return '微信'
}
const getTime = data => {
  if (data === 1) return '不限'
  if (data === 2) return '工作日'
  if (data === 3) return '双休或假日'
}
const getpayType = data => {
  if (data === 1) return '在线支付'
  if (data === 2) return '货到付款'
}
const goodDel = ref()
const openDialog = () => {
  goodDel.value.show = true
  goodDel.value.id = data.value.id
}
const buyAgain = () => {
  router.push('/orderpage/' + data.value.id)
  // memberOrderRepurchaseId()
  // 151515asddasf
}
const goPay = () => {
  router.push('/pay/' + data.value.id)
}
</script>
<template>
  <div class="orderdetil" v-if="data">
    <div class="top">
      <div class="icon">
        <el-icon style="color: #27ba9b; font-size: 40px"><BellFilled /></el-icon>
        <span class="text">{{ getState(data.orderState) }}</span>
      </div>
      <div class="orderMessage">
        <div class="oM-Top">订单编号：{{ data.id }}</div>
        <div class="butto">订单时间：{{ data.createTime }}</div>
      </div>
      <el-button
        style="background-color: #27ba9b; color: white"
        v-if="
          data.orderState === 2 ||
          data.orderState === 4 ||
          data.orderState === 3 ||
          data.orderState === 4
        "
        @click="buyAgain"
        >再次购买</el-button
      >
      <el-button
        style="background-color: #27ba9b; color: white"
        v-if="data.orderState === 1"
        @click="goPay"
        >立即支付</el-button
      >
      <el-button
        style="background-color: #cccccc; color: white"
        v-if="data.orderState === 1"
        @click="openDialog"
        >取消订单</el-button
      >
      <el-button
        style="background-color: #cccccc; color: white"
        v-if="data.orderState === 4 || data.orderState === 4"
        >申请售后</el-button
      >
      <el-button
        style="background-color: #e6faf6; color: #27ba9b; border: 1px solid #27ba9b"
        v-if="data.orderState === 4"
        >评价商品</el-button
      >
    </div>
    <div class="steps">
      <el-steps style="max-width: 900px" :active="active" align-center>
        <el-step title="提交订单">
          <template #description>
            <div>{{ data.createTime }}</div>
          </template>
        </el-step>
        <el-step title="付款成功">
          <template #description>
            <div v-if="data.payTime">{{ data.payTime }}</div>
          </template>
        </el-step>
        <el-step title="商品发货">
          <template #description>
            <div v-if="data.consignTime">{{ data.consignTime }}</div>
          </template>
        </el-step>
        <el-step title="确认收货">
          <template #description>
            <div v-if="data.endTime">{{ data.endTime }}</div>
          </template>
        </el-step>
        <el-step title="订单完成">
          <template #description>
            <div v-if="data.closeTime">{{ data.closeTim }}</div>
          </template>
        </el-step>
      </el-steps>
    </div>
    <div class="goods">
      <div style="margin-bottom: 20px">订单商品</div>
      <el-table ref="multipleTableRef" :data="tableData" style="width: 100%">
        <el-table-column label="商品信息" align="center" width="500">
          <template #default="row">
            <div class="goodDet">
              <img :src="row.row.image" alt="" class="goodImg" />
              <div class="content">
                <div class="top">{{ row.row.name }}</div>
                <div class="but">
                  <div class="con">
                    {{ row.row.attrsText }}
                  </div>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="单价" width="">
          <template #default="row">
            <span>￥{{ row.row.curPrice }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" property="quantity" width="" label="数量">
        </el-table-column>
        <el-table-column align="center" width="" label="小计">
          <template #default="row">
            <span class="totalMoney">￥{{ row.row.curPrice * row.row.quantity }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" width="" label="实付">
          <template #default="row">
            <span class="totalMoney">￥{{ row.row.realPay }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="items">
      <div class="title">收货信息</div>
      <div class="main">
        <div><span>收货人：</span>{{ data.receiverContact }}</div>
        <div><span>联系方式：</span>{{ data.receiverMobile }}</div>
        <div><span>收货地址:</span>{{ data.receiverAddress }}</div>
      </div>
    </div>
    <div class="items">
      <div class="title">支付方式及送货时间</div>
      <div class="main">
        <div><span>支付方式：</span>{{ getChannel(data.payChannel) }}</div>
        <div><span>送货时间：</span>{{ getTime(data.deliveryTimeType) }}</div>
      </div>
    </div>
    <div class="items">
      <div class="title">订单信息</div>
      <div class="main">
        <div><span>支付方式：</span>{{ getpayType(data.payType) }}</div>
        <div><span>下单时间：</span>{{ data.createTime }}</div>
      </div>
    </div>
    <div class="foot">
      <div class="item">
        <div class="title">商品件数：</div>
        <span>{{ data.totalNum }}件</span>
      </div>
      <div class="item">
        <div class="title">商品总价：</div>
        <span>￥{{ data.totalMoney }}</span>
      </div>
      <div class="item">
        <div class="title">运费：</div>
        <span>{{ data.postFee }}</span>
      </div>
      <div class="item">
        <div class="title">应付总额：</div>
        <span style="color: red">￥{{ data.payMoney }}</span>
      </div>
    </div>
  </div>
  <good-dialog ref="goodDel"></good-dialog>
</template>
<style scoped lang="scss">
.orderdetil {
  background-color: #fff;
  box-sizing: border-box;
  padding: 50px;
  width: 1000px;
  .top {
    margin-bottom: 85px;
    display: flex;
    .icon {
      position: relative;
      .text {
        text-align: center;
        font-size: 13px;
        position: absolute;
        bottom: -10px;
        left: 0;
      }
    }
    .orderMessage {
      margin-left: 80px;
      color: grey;
      flex: 1;
      .oM-Top {
        margin-bottom: 10px;
      }
      .butto {
      }
    }
  }
  .goods {
    margin-top: 50px;
    .goodDet {
      display: flex;
      .goodImg {
        height: 100px;
        width: 100px;
        padding-right: 10px;
      }
      .content {
        padding-top: 15px;
        font-size: 17px;
        flex: 1;
        line-height: 30px;

        .but {
          color: #999999;
          text-align: left;
          .con {
            height: 30px;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 287px;
          }
        }
        .top {
          margin-bottom: 10px;
          height: 30px;
          overflow: hidden;
          text-overflow: ellipsis;
          padding-bottom: 10px;
          text-align: left;
        }
      }
    }
  }
  .steps {
  }
  .items {
    margin-top: 20px;
    .main {
      padding: 10px 20px;
      margin-top: 20px;
      border: 1px solid gray;
      span {
        color: grey;
      }
      div {
        margin: 10px 0;
      }
    }
  }
  .foot {
    margin-left: auto;
    width: 250px;
    .item {
      margin: 10px 0;
      display: flex;
      .title {
        flex: 1;
      }
    }
  }
}
</style>
